<?php

namespace app\index\controller\rush;

use app\index\model\UM as UM;
use app\index\service\ConsultingRushService;
use ShidianUtil\Thinkphp\Response\ApiResponse;
use think\APP;
use think\exception\ValidateException;
use think\Request as Request;

/**
 * ConsultingRush 控制器
 * Class ConsultingRush
 * @package app\index\controller\rush;
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037509
 */
class ConsultingRush
{
    // 请求参数
    private Request $request;

    // service
    private ConsultingRushService $service;

    public function __construct(Request $request, ConsultingRushService $consultingRushService)
    {
        $this->request = $request;
        $this->service = $consultingRushService;
    }

    /**
     * 列表
     * @param UM|null $user
     * @return ApiResponse
     * @url /rush/consulting_rush/index
     */
    public function index(?UM $user): ApiResponse
    {
        $request = $this->request;

        $categoryId = $request->param('categoryId',);
        $cityId = $request->param('cityId');
        $page = $request->param('page', 1);
        $page_size = $request->param('page_size', 20);

        if(!$user){
            return ApiResponse::success([]);
        }

        return ApiResponse::success($this->service->index($user, $categoryId, $cityId, $page, $page_size));
    }

}
